<?php

if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
$grouplistmanage = amygrouplist($_G['uid'], 'lastupdate', array(0 => 'f.name', 1 => 'ff.icon'), 30, 0, 1);
$grouplistjiaru = amygrouplist($_G['uid'], 'lastupdate', array(0 => 'f.name', 1 => 'ff.icon'), 30, 0, 2);
function agrouplist($orderby = 'displayorder', $fieldarray = array(), $num = 1, $fids = array(), $sort = 0, $getcount = 0, $grouplevel = array())
{
    $query = C::t('forum_forum')->fetch_all_for_grouplist($orderby, $fieldarray, $num, $fids, $sort, $getcount);
    if ($getcount) {
        return $query;
    }
    $grouplist = array();
    foreach ($query as $group) {
        $group['iconstatus'] = $group['icon'] ? 1 : 0;
        if (isset($group['icon'])) {
            $group['icon'] = aget_groupimg($group['icon'], 'icon');
        }
        if (isset($group['banner'])) {
            $group['banner'] = aget_groupimg($group['banner']);
        }
        $group['orderid'] = $orderid ? intval($orderid) : '';
        $group['level'] = !empty($grouplevel) ? intval($grouplevel[$group['fid']]) : 0;
        if (isset($group['description'])) {
            $group['description'] = cutstr($group['description'], 130);
        }
        $grouplist[$group['fid']] = $group;
        $orderid = $orderid + 1;
    }
    return $grouplist;
}
function amygrouplist($uid, $orderby = '', $fieldarray = array(), $num = 0, $start = 0, $ismanager = 0, $count = 0)
{
    $uid = intval($uid);
    if (empty($uid)) {
        return array();
    }
    $grouplevel = array();
    $groupfids = $grouplevel;
    $query = C::t('forum_groupuser')->fetch_all_group_for_user($uid, $count, $ismanager, $start, $num);
    foreach ($query as $group) {
        $groupfids[] = $group['fid'];
        $grouplevel[$group['fid']] = $group['level'];
    }
    if (empty($groupfids)) {
        return false;
    }
    $mygrouplist = agrouplist($orderby, $fieldarray, $num, $groupfids, 0, 0, $grouplevel);
    return $mygrouplist;
}
function aget_groupimg($imgname, $imgtype = '')
{
    global $_G;
    $imgpath = $_G['setting']['attachurl'] . 'group/' . $imgname;
    if ($imgname) {
        return $imgpath;
    }
    if ($imgtype == 'icon') {
        return 'static/image/common/groupicon.gif';
    }
    return '';
}